home *** CD-ROM | disk | FTP | other *** search
- <%
- '+-------------------------------------------------------------------------
- '
- ' Microsoft Windows Media
- ' Copyright (C) Microsoft Corporation. All rights reserved.
- '
- ' File: Error.asp
- '
- ' Contents: common error-handling utilities
- '
- '--------------------------------------------------------------------------
-
- '/////////////////////////////////////////////////////////////////////////////////////
- ' Debugging tool- display a javascript popup with s specified string
- '/////////////////////////////////////////////////////////////////////////////////////
- sub DebugDialog( strDebugInfo )
- Dim strOutputString
- if( "\" = mid( strDebugInfo, Len( strDebugInfo ), 1 ) ) then
- strDebugInfo = strDebugInfo & "\"
- end if
- strDebugInfo = Server.HTMLEncode( strDebugInfo )
- strOutputString = "<script language=javascript> alert" & chr(40) & chr(34) & Server.HTMLEncode( CStr( strDebugInfo ) ) & chr(34) & chr(41) & ";</script>"
- Response.Write ( chr(13) & strOutputString & chr(13 ) )
- End Sub
-
- '/////////////////////////////////////////////////////////////////////////////////////
- ' Debugging tool- display each query string name and arg in a simple table
- '/////////////////////////////////////////////////////////////////////////////////////
- sub DumpQueryString()
- exit sub ' remove this line if you wish to make use of this subroutine
- Dim objQSItem
- on error resume next
- %>
- <div>
- <table valign="top" cellspacing="1" cellpadding="1" bgcolor="silver" border="1">
- <th colspan=2>
- <b>QueryString: <%= Request.QueryString.count %></b>
- </th><%
-
- for each objQSItem in Request.QueryString %>
- <tr>
- <td> <%= Server.HTMLEncode( objQSItem ) %> </td>
- <td><%= Server.HTMLEncode( Request.QueryString( objQSItem ) ) %> </td>
- </tr><%
- next %>
- </table>
- </div>
- <%
- objQSItem = nothing
- End Sub
-
- '/////////////////////////////////////////////////////////////////////////////////////
- ' Debugging tool- display each posted form's name and arg in a simple table
- '/////////////////////////////////////////////////////////////////////////////////////
- sub DumpFormPosting()
- exit sub ' remove this line if you wish to make use of this subroutine
- Dim objFormItem
- on error resume next
- %>
- <div>
- <table valign="top" cellspacing="1" cellpadding="1" bgcolor="silver" border="1">
- <th colspan="2">
- <b>Form Posting Element count: <%= Request.Form.count %></b>
- </th><%
- for each objFormItem in Request.Form %>
- <tr>
- <td> <%= Server.HTMLEncode( objFormItem ) %> </td>
- <td> <%= Server.HTMLEncode( Request.Form( objFormItem ) ) %> </td>
- </tr><%
- next %>
- </table>
- </div>
- <%
- objFormItem = nothing
- End Sub
-
- '/////////////////////////////////////////////////////////////////////////////////////
- ' Debugging tool- dump IIS server variables in a simple table
- '/////////////////////////////////////////////////////////////////////////////////////
- sub DumpServerVariables()
- exit sub ' remove this line if you wish to make use of this subroutine
- dwNumVars = Request.ServerVariables.Count
-
- Response.Write( "<br>Number of server variables: " & dwNumVars )
- for i = 1 to dwNumVars
- Response.Write( "<br>" & Server.HTMLEncode( Request.ServerVariables.Key( i ) ) & " : " & Server.HTMLEncode( Request.ServerVariables.Item( i ) ) )
- next
- End Sub
-
- '/////////////////////////////////////////////////////////////////////////////////////
- ' Initialize the error handler for the current page
- '/////////////////////////////////////////////////////////////////////////////////////
- sub BeginErrorHandling()
- if 0 = Session( "PageReloadedToDisplayError" ) then
- Session( "ErrorNumber" ) = 0
- Session( "ErrorCulprit" ) = ""
- Session( "ErrorDescription" ) = ""
- Err.Clear
- ClearError
- end if
- End Sub
-
-
- '/////////////////////////////////////////////////////////////////////////////////////
- '
- ' Called at the bottom of a page implementing error handling. Determines if we need
- ' to re-load the page to display error messages or just clear the error state vars.
- '
- sub EndErrorHandling( WhichASPFile )
-
- if( 0 = Session( "ErrorNumber" ) ) then
- ClearError
- elseif ( 0 <> Session( "PageReloadedToDisplayError" ) ) then
- Session( "PageReloadedToDisplayError" ) = 0
- ClearError
- else
- Session( "PageReloadedToDisplayError" ) = 1
- Response.Redirect( WhichASPFile & "?" & RemoveDangerousCharacters( Request.QueryString ) )
- end if
-
- End Sub
-
-
- '/////////////////////////////////////////////////////////////////////////////////////
- '
- ' Returns a bool indicating if an error was detected. Primes some state variables
- ' so that we can call AlertUserWithPopupErrorDialog and OnErrorGoBack later on the page
- '
- function ErrorDetected( strCulprit )
- dim bErrorDetected
- dim strWMSDescription
- dim dwSavedErrorNum
- dim strSavedErrorDescription
-
- bErrorDetected = FALSE
-
- if 0 <> Err.number then
- if( 0 = Session( "ErrorNumber" ) ) then
- bErrorDetected = TRUE
-
- if( -1 = Err.Number ) then
-
- Session( "ErrorDescription" ) = Err.Description
- Session( "ErrorNumber" ) = Err.Number
- Session( "ErrorCulprit" ) = strCulprit
-
- else
-
- dwSavedErrorNum = Err.Number
- strSavedErrorDescription = Err.Description
-
- on error resume next
- err.number = dwSavedErrorNum
- err.description = strSavedErrorDescription
-
- strWMSDescription = s_WMSAdmin.Error( dwSavedErrorNum )
- if( "" <> strWMSDescription ) then
- Session( "ErrorDescription" ) = strWMSDescription
- else
- if( 450 = dwSavedErrorNum ) then
- Session( "ErrorDescription" ) = L_UNSPECIFIEDERR_TEXT
- Session( "ErrorNumber" ) = "?"
- else
- Session( "ErrorDescription" ) = strSavedErrorDescription
- end if
- end if
- Session( "ErrorNumber" ) = dwSavedErrorNum
- Session( "ErrorCulprit" ) = strCulprit
-
- end if
- end if
- end if
-
- ErrorDetected = bErrorDetected
-
- end function
-
-
- '/////////////////////////////////////////////////////////////////////////////////////
- '
- ' Called at the bottom of a page when it reloads. Requires JavaScript on the browser
- '
- sub AlertUserWithPopupErrorDialog()
- if 0 <> Session( "ErrorNumber" ) then
- Dim strError, strError2, strErrorWithoutLF, dwOffsetToQuoteChar
-
- strError = Session( "ErrorDescription" )
-
- ' Remove illegal chars and work around quote chars
- dwOffsetToQuoteChar = InStr( 1, strError, chr(34), vbTextCompare )
- if( 0 <= dwOffsetToQuoteChar ) then
- strError = Replace( strError, chr(34), "\" & chr(34), 1, Len( strError ), vbTextCompare )
- end if
-
- strError = L_ERRORDESCRIPTION_TEXT & strError
-
- Dim strHexValue
- strHexValue = Hex( Session( "ErrorNumber" ) )
- if( -1 = Session( "ErrorNumber" ) ) then
- strError = Session( "ErrorDescription" )
- else
- strError2 = L_ERRORCODE_TEXT & Server.HTMLEncode( strHexValue )
- end if
-
- %>
- <script language="JavaScript">
- window.alert( "<%= strError %>" + "\n" + "<%= strError2 %>" );
- </script>
- <%
- end if
- End Sub
-
-
- '/////////////////////////////////////////////////////////////////////////////////////
- '
- ' If an error is detected, insert javascript to take the user to the previously visited
- ' page, taking care to wipe the current page out of the browser's history buffer
- '
- sub OnErrorGoBack()
- if 0 <> Session( "ErrorNumber" ) then
- Response.Write( chr(13) & "<script language=JavaScript>" & chr(13) & "window.history.back();" & chr(13) & "</script>" )
- end if
- End Sub
-
-
- '/////////////////////////////////////////////////////////////////////////////////////
- '
- ' If an error was saved and we're printing the culprit, display it in error formatted
- ' text. Otherwise, just print the text string.
- '
- sub RenderWithErrorCheck( ByRef strTextToPrint, ByRef strCulprit )
- if 0 = Session( "ErrorNumber" ) then
- Response.Write strTextToPrint
- elseif ( 0 <> StrComp( strCulprit, Session( "ErrorCulprit" ), vbTextCompare ) ) then
- Response.Write strTextToPrint
- else
- Response.Write "<b><font color=" & chr(34) & "red" & chr(34) & ">"
- Response.Write strTextToPrint
- Response.Write "</b></font>"
- end if
- End Sub
-
- '/////////////////////////////////////////////////////////////////////////////////////
- ' PRIVATE SUBROUTINES
- '/////////////////////////////////////////////////////////////////////////////////////
-
-
- '/////////////////////////////////////////////////////////////////////////////////////
- '
- ' Clear the error information. Should ONLY be called by ErrorCleanUp.
- '
- Sub ClearError()
- Session( "ErrorNumber" ) = 0
- Session( "ErrorDescription" ) = ""
- Session( "ErrorCulprit" ) = ""
- Err.Clear
- Session( "PageReloadedToDisplayError" ) = 0
- End Sub
- %>
-